//
// PowerUp - Mercenary Camp
//
// L. Dean Gibson II 2/8/01
//
//
// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "adv_mercenary_camp.h"

#include "adv_object_type.h"
#include "ai_value.h"
#include "basic_dialog.h"
#include "creature_array.h"
#include "hero.h"
#include "object_registration.h"
#include "replace_keywords.h"

static t_object_registration<t_adv_mercenary_camp> 
       k_registration( k_adv_object_mercenary_camp );


// -------------------------------------------------------------
// hero gains +1 Speed permanently for free
// -------------------------------------------------------------
t_adv_mercenary_camp::t_adv_mercenary_camp(  std::string const& source )
         : t_single_use_object( source )
{
}


// -------------------------------------------------------------
// hero gains +1 Speed permanently for free
// -------------------------------------------------------------
std::string t_adv_mercenary_camp::add_icons( t_basic_dialog* dialog, std::string const& text, std::vector<t_hero*> const& heroes )
{
	dialog->add_speed( 1 );
	return replace_keywords( text, "%speed", "1" );
}

// -------------------------------------------------------------
// hero gains +1 Speed permanently for free
// -------------------------------------------------------------
void t_adv_mercenary_camp::visit( t_hero* hero )
{
	hero->add_bonus( k_stat_speed, 1 );
}

// -------------------------------------------------------------
// hero gains +1 Speed permanently for free
// -------------------------------------------------------------
float t_adv_mercenary_camp::ai_value( t_adventure_ai const& ai, t_creature_array const& army, int move_cost ) const
{
	float total_value = 0.0f;
	for (int i = 0; i < t_creature_array::k_size; i++)
	{
		t_creature_stack const& stack = army[i];
		t_hero const* hero = stack.get_const_hero();
		if (!hero || hero->has_visited(*this)) continue;
		total_value += ai_value_of_additional_speed(&stack, 1) * 1.5f; // 50% more because it's permenant.
	}		
	return total_value;
}
